﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ToolwebAQ.database;
using Ultility;

namespace ToolwebAQ
{
    public partial class master : System.Web.UI.MasterPage
    {
        string noidung = "";
        aquariusDBDataContext db = new aquariusDBDataContext();
        tool tl = new tool();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    loadtopmenu2();
                }
                catch (Exception)
                {

                    throw;
                }
            }
        }
        void loadtopmenu()
        {
            //var listmenu = db.sp_TreeDataTbl_layout_selecttopmenu.ToList();

            //foreach (var item in listmenu)
            //{
            //    noidung += "<li>";
            //    if (item.urlpage.Trim() == "Nhập url page")
            //    {

            //        noidung += " <img src='" + "../" + item.imgpath + "' alt='" + item.Tree_Name + "' />";
            //        noidung += "<a href=default.aspx>" + item.Tree_Name + "</a>";
            //        noidung += "<div class='menu_hover'>";
            //        noidung += "<span>";

            //        var listsubmenu = db.Sp_TreeDataTbl_layout_slect_Parent_ID(int.Parse(item.Tree_ID.ToString())).ToList();
            //        for (int i = 1; i < listsubmenu.Count(); i++)
            //        {

            //            foreach (var item1 in listsubmenu)
            //            {
            //                if (item1.urlpage.ToString().Trim() == "Nhập url page")
            //                {

            //                    noidung += "<a href=" + item1.urlpage.ToString().Trim() + ">" + item1.Tree_Name.ToString() + "</a>";

            //                }
            //                else
            //                {

            //                    noidung += "<a href=" + item1.urlpage.ToString().Trim() + ">" + item1.Tree_Name.ToString() + "</a>";

            //                }
            //            }

            //        }
            //        noidung += "</span>";
            //        noidung += "</div>";

            //    }
            //    else
            //    {

            //        noidung += " <img src='" + "../" + item.imgpath + "' alt='" + item.Tree_Name + "' />";
            //        noidung += "<a href=" + item.urlpage + ">" + item.Tree_Name + "</a>";
            //        noidung += "<div class='menu_hover'>";
            //        noidung += "<span>";
            //        var listsubmenu = db.Sp_TreeDataTbl_layout_slect_Parent_ID(int.Parse(item.Tree_ID.ToString())).ToList();
            //        for (int i = 1; i < listsubmenu.Count(); i++)
            //        {

            //            foreach (var item1 in listsubmenu)
            //            {
            //                if (item1.urlpage.ToString().Trim() == "Nhập url page")
            //                {

            //                    noidung += "<a href=" + item1.urlpage.ToString().Trim() + ">" + item1.Tree_Name.ToString() + "</a>";

            //                }
            //                else
            //                {

            //                    noidung += "<a href=" + item1.urlpage.ToString().Trim() + ">" + item1.Tree_Name.ToString() + "</a>";

            //                }
            //            }

            //        }
            //        noidung += "</span>";
            //        noidung += "</div>";
            //    }
            //    noidung += "</li>";
            //}
            //topmenu.InnerHtml = noidung;

        }

        public void loadlan(string lan)
        {
            HttpCookie cookie = Request.Cookies["SelLang"];
            cookie.Value = lan;
            Session["flag"] = lan;
            cookie.Expires = DateTime.Now.AddYears(1);
            Response.SetCookie(cookie);
            Response.Redirect(Request.UrlReferrer.AbsoluteUri);
        }



        void loadtopmenu2()
        {
            if (Session["flag"] == null)
            {
                Session["flag"] = Resources.MainMaster.Vietnam;
            }
            var listmenu = db.view_human_tree_menu_layout_menu(Session["flag"].ToString()).ToList();

            foreach (var item in listmenu)
            {
                noidung += "<li>";
                if (item.urlpage.Trim() == "Nhập url page")
                {

                    noidung += " <img src='" + "../" + item.imgpath + "' alt='" + item.imgpath + "' />";
                    noidung += "<a href=AQDefault.aspx>" + item.Tree_Name + "</a>";
                    noidung += "<div class='menu_hover'>";
                    noidung += "<span>";

                    var listsubmenu = db.Sp_TreeDataTbl_layout_slect_Parent_ID(int.Parse(item.Tree_ID.ToString())).ToList();


                    foreach (var item1 in listsubmenu)
                    {
                        if (item1.urlpage.ToString().Trim() == "Nhập url page")
                        {

                            noidung += "<a href=" + item1.urlpage.ToString().Trim() + ">" + item1.Tree_Name.ToString() + "</a>";

                        }
                        else
                        {

                            noidung += "<a href=" + item1.urlpage.ToString().Trim() + ">" + item1.Tree_Name.ToString() + "</a>";

                        }
                    }


                    noidung += "</span>";
                    noidung += "</div>";
                }
                else
                {

                    noidung += " <img src='" + "../" + item.imgpath + "' alt='" + item.Tree_Name + "' />";
                    noidung += "<a href=" + item.urlpage + ">" + item.Tree_Name + "</a>";
                    noidung += "<div class='menu_hover'>";
                    noidung += "<span>";
                    var listsubmenu = db.Sp_TreeDataTbl_layout_slect_Parent_ID(int.Parse(item.Tree_ID.ToString())).ToList();
                    for (int i = 1; i < listsubmenu.Count(); i++)
                    {

                        foreach (var item1 in listsubmenu)
                        {
                            if (item1.urlpage.ToString().Trim() == "Nhập url page")
                            {

                                noidung += "<a href=" + item1.urlpage.ToString().Trim() + ">" + item1.Tree_Name.ToString() + "</a>";

                            }
                            else
                            {

                                noidung += "<a href=" + item1.urlpage.ToString().Trim() + ">" + item1.Tree_Name.ToString() + "</a>";

                            }
                        }

                    }
                    noidung += "</span>";
                    noidung += "</div>";
                }
                noidung += "</li>";
            }
            topmenu.InnerHtml = noidung;
        }

        protected void img_tv_Click(object sender, ImageClickEventArgs e)
        {
            loadlan("vi");
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            loadlan("en");
        }


    }
}

